package com.surfilter.platform.base.service;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
/**
 * 
 * 用于从Spring IOC容器中直接获取bean
 * 
 */
public class SpringContextUtil implements ApplicationContextAware {

	private static ApplicationContext applicationContext;

	public void setApplicationContext(ApplicationContext arg0)
			throws BeansException {
		SpringContextUtil.applicationContext = arg0;
	}

	public static Object getBean(String beanName) {
		return applicationContext.getBean(beanName);
	}

	public static <T> T getBean(String beanName, Class<T> cls) {
		return applicationContext.getBean(beanName, cls);
	}

	public static <T> T getBean(Class<T> cls) {
		return applicationContext.getBean(cls);
	}

	public static boolean isSingleton(String beanName) {
		return applicationContext.isSingleton(beanName);
	}

	public static boolean isPrototype(String beanName) {
		return applicationContext.isPrototype(beanName);
	}

	public static boolean containsBean(String beanName) {
		return applicationContext.containsBean(beanName);
	}

}
